<?php
	include_once '../config/config.php';
	$login = $_POST["login"];
	$password = md5($_POST["password"]);
	$email = $_POST["email"];
	$sql="INSERT INTO user (login, password, email) VALUES (?,?,?)";
	$pdo->prepare($sql)->execute(array($login, $password, $email));
	session_start();
	$_SESSION['login'] = $login;
	$chatLogPath = "../coreChat/log/chatLog.txt";
	$data = "<font color='#0a0'>--- ".$_SESSION['login']." is a new user"." ---</font><br/>";
	file_put_contents($chatLogPath, $data, FILE_APPEND);
	//Generate random color for the current user
	$randomcolor = '#' . strtoupper(dechex(rand(0,10000000)));
	$_SESSION['loginColor'] = $randomcolor;
	header("Location: ../coreChat/chat.php");
?>